
# class Data():
#     def __init__(self) -> None:
#         self.latest = {}
#         self.

# DATA_ID_DEBUG = 1
# DATA_ID_IMU = 2
# DATA_ID_ROBOT_INFO = 3

SEND_ID_ROBOT_CMD = 1
SEND_ID_VIRTUAL_RC = 3

class Imu_Data():
    def __init__(self) -> None:
        self.latest = {
            "time_stamp":0, # 时间戳(s)
            
            "yaw":0,   # 偏航角(rad)
            "pitch":0, # 俯仰角(rad)
            "roll":0,  # 横滚角(rad)
            
            "yaw_vel":0,   # 偏航角速度(rad/s)
            "pitch_vel":0, # 俯仰角速度(rad/s)
            "roll_vel":0,  # 横滚角速度(rad/s)
        }
        
        self.storage = {
            "time_stamp":[],
            
            "yaw":[],
            "pitch":[],
            "roll":[],
            
            "yaw_vel":[],
            "pitch_vel":[],
            "roll_vel":[],
        }
        self.length = len(self.storage['time_stamp'])
        return

    ############################################################
    #  基本功能
    #  update 更新数据
    #  clear 清空数据
    #  limit 限制数据长度
    ############################################################

    def update(self,data:dict) -> None:
        self.latest = data.copy()
        
        self.storage['time_stamp'].append(data['time_stamp'])
        
        self.storage['yaw'].append(data['yaw'])
        self.storage['pitch'].append(data['pitch'])
        self.storage['roll'].append(data['roll'])
        
        self.storage['yaw_vel'].append(data['yaw_vel'])
        self.storage['pitch_vel'].append(data['pitch_vel'])
        self.storage['roll_vel'].append(data['roll_vel'])
        
        self.length = len(self.storage['time_stamp'])
        return
    
    def clear(self) -> None:
        self.latest = {
            "yaw":0,
            "pitch":0,
            "roll":0,
            
            "yaw_vel":0,
            "pitch_vel":0,
            "roll_vel":0,
        }
        
        for key in self.storage:
            self.storage[key].clear()
        
        self.length = len(self.storage['time_stamp'])
        return
    
    def limit(self,length:int) -> None:
        for key in self.storage:
            self.storage[key] = self.storage[key][-length:]
        self.length = len(self.storage['time_stamp'])
        return
        
        
class Debug_Data():
    def __init__(self) -> None:
        self.latest = {
            "time_stamp":0, # 时间戳(s)
            "datas":{}, # 数据
        }
        
        self.storage = {
            "time_stamp":[],
            "datas":{},
        }
        self.length = len(self.storage['time_stamp'])
        return
    
    ############################################################
    #  基本功能
    #  update 更新数据
    #  clear 清空数据
    #  limit 限制数据长度
    ############################################################

    def update(self,data:dict) -> None:
        self.latest = data.copy()
        
        self.storage['time_stamp'].append(data['time_stamp'])
        
        for key in data['datas']:
            if key not in self.storage['datas']:
                self.storage['datas'][key] = []
            self.storage['datas'][key].append(data['datas'][key])
        
        self.length = len(self.storage['time_stamp'])
        return

    def clear(self) -> None:
        self.latest = {
            "time_stamp":0, # 时间戳(s)
            
            "datas":{}, # 数据
        }
        
        self.storage["time_stamp"].clear()

        self.storage["datas"] = {}

        self.length = len(self.storage['time_stamp'])
        return

    def limit(self,length:int) -> None:
        self.storage['time_stamp'] = self.storage['time_stamp'][-length:]
        
        for key in self.storage['datas']:
            self.storage['datas'][key] = self.storage['datas'][key][-length:]
        
        self.length = len(self.storage['time_stamp'])
        return


class Robot_Info_Data():
    def __init__(self) -> None:
        self.clear()
        return
    ############################################################
    #  基本功能
    #  update 更新数据
    #  clear 清空数据
    ############################################################

    def update(self,data:dict) -> None:
        self.latest = data.copy()
        return

    def clear(self) -> None:
        self.latest = {
                'time_stamp': 0,
                'types': {
                        'chassis': 0,
                        'gimbal': 0,
                        'shoot': 0,
                        'arm': 0,
                        'custom_controller': 0,
                        },
                'state': {
                        'chassis':False,
                        'gimbal':False,
                        'shoot':False,
                        'arm':False,
                        'custom_controller':False,
                        },
                # 'referee': {
                #         'id': 0,
                #         'color':0,
                #         'attacked':False,
                #         'hp':0,
                #         'heat':0,
                #         },
            }
        return


class Event_Data():
    def __init__(self) -> None:
        self.clear()
        return
    ############################################################
    #  基本功能
    #  update 更新数据
    #  clear 清空数据
    ############################################################

    def update(self,data:dict) -> None:
        self.latest = data.copy()
        return

    def clear(self) -> None:
        self.latest = {
                'time_stamp': 0,# 时间戳(s)

                'non_overlapping_supply_zone':False,
                'overlapping_supply_zone':False,
                'supply_zone':False,

                'small_energy':False,
                'big_energy':False,

                'central_highland':0,
                'trapezoidal_highland':0,

                'center_gain_zone':0,

                'base_virtual_shield_remaining':0,
            }
        return


class Pid_Debug_Data():
    def __init__(self) -> None:
        self.clear()
        return
    ############################################################
    #  基本功能
    #  update 更新数据
    #  clear 清空数据
    ############################################################

    def update(self,data:dict) -> None:
        self.latest = data.copy()
        return

    def clear(self) -> None:
        self.latest = {
                'time_stamp': 0,
                
                'fdb': 0,
                'ref': 0,
                'pid_out': 0,

            }
        return

class All_Robot_HP_Data():
    def __init__(self) -> None:
        self.clear()
        return
    ############################################################
    #  基本功能
    #  update 更新数据
    #  clear 清空数据
    ############################################################

    def update(self,data:dict) -> None:
        self.latest = data.copy()
        return
    
    def clear(self) -> None:
        self.latest = {
                'time_stamp': 0,
                
                'red_1_robot_hp': 0,
                'red_2_robot_hp': 0,
                'red_3_robot_hp': 0,
                'red_4_robot_hp': 0,
                'red_7_robot_hp': 0,
                'red_outpost_hp': 0,
                'red_base_hp'   : 0,

                'blue_1_robot_hp': 0,
                'blue_2_robot_hp': 0,
                'blue_3_robot_hp': 0,
                'blue_4_robot_hp': 0,
                'blue_7_robot_hp': 0,
                'blue_outpost_hp': 0,
                'blue_base_hp'   : 0,

            }
        return

class Game_Status_Data():
    def __init__(self) -> None:
        self.clear()
        return
    ############################################################
    #  基本功能
    #  update 更新数据
    #  clear 清空数据
    ############################################################

    def update(self,data:dict) -> None:
        self.latest = data.copy()
        return

    def clear(self) -> None:
        self.latest = {
                'time_stamp': 0,
                
                'game_progress': 0,
                'stage_remain_time': 0,
                
            }
        return

class Robot_Motion_Data():
    def __init__(self) -> None:
        self.clear()
        return
    ############################################################
    #  基本功能
    #  update 更新数据
    #  clear 清空数据
    ############################################################

    def update(self,data:dict) -> None:
        self.latest = data.copy()
        return

    def clear(self) -> None:
        self.latest = {
                'time_stamp': 0,
                
                'speed_vector':{
                    'vx': 0,
                    'vy': 0,
                    'wz': 0,
                },
            }
        return

class Ground_Robot_Position_Data():
    def __init__(self) -> None:
        self.clear()
        return
    ############################################################
    #  基本功能
    #  update 更新数据
    #  clear 清空数据
    ############################################################

    def update(self,data:dict) -> None:
        self.latest = data.copy()
        return

    def clear(self) -> None:
        self.latest = {
                'time_stamp': 0,
                
                'hero_x':0,
                'hero_y':0,

                'engineer_x':0,
                'engineer_y':0,

                'standard_3_x':0,
                'standard_3_y':0,

                'standard_4_x':0,
                'standard_4_y':0,

                'standard_5_x':0,
                'standard_5_y':0,
            }
        return

class Rfid_Status_Data():
    def __init__(self) -> None:
        self.clear()
        return
    ############################################################
    #  基本功能
    #  update 更新数据
    #  clear 清空数据
    ############################################################

    def update(self,data:dict) -> None:
        self.latest = data.copy()
        return

    def clear(self) -> None:
        self.latest = {
                'time_stamp': 0,
                
                'base_gain_point' : False,
                'central_highland_gain_point' : False,
                'enemy_central_highland_gain_point' : False,
                'friendly_trapezoidal_highland_gain_point' : False,
                'enemy_trapezoidal_highland_gain_point' : False,
                'friendly_fly_ramp_front_gain_point' : False,
                'friendly_fly_ramp_back_gain_point' : False,
                'enemy_fly_ramp_front_gain_point' : False,
                'enemy_fly_ramp_back_gain_point' : False,
                'friendly_central_highland_lower_gain_point' : False,
                'friendly_central_highland_upper_gain_point' : False,
                'enemy_central_highland_lower_gain_point' : False,
                'enemy_central_highland_upper_gain_point' : False,
                'friendly_highway_lower_gain_point' : False,
                'friendly_highway_upper_gain_point' : False,
                'enemy_highway_lower_gain_point' : False,
                'enemy_highway_upper_gain_point' : False,
                'friendly_fortress_gain_point' : False,
                'friendly_outpost_gain_point' : False,
                'friendly_supply_zone_non_exchange' : False,
                'friendly_supply_zone_exchange' : False,
                'friendly_big_resource_island' : False,
                'enemy_big_resource_island' : False,
                'center_gain_point' : False,
            }
        return

class Robot_Status_Data():
    def __init__(self) -> None:
        self.clear()
        return
    ############################################################
    #  基本功能
    #  update 更新数据
    #  clear 清空数据
    ############################################################

    def update(self,data:dict) -> None:
        self.latest = data.copy()
        return

    def clear(self) -> None:
        self.latest = {
                'time_stamp': 0,
                
                'robot_id': 0,
                'robot_level': 0,
                'current_up': 0,
                'maximum': 0,
                'shooter_barrel_cooling_value': 0,
                'shooter_barrel_heat_limit': 0,

                'shooter_17mm_1_barrel_heat': 0,

                'robot_pos_x': 0,
                'robot_pos_y': 0,
                'robot_pos_angle': 0,

                'armor_id': 0,
                'hp_deduction_reason': 0,

                'projectile_allowance_17mm_1': 0,
                'remaining_gold_coin': 0,
            }
        return

class Joint_State_Data():
    def __init__(self) -> None:
        self.clear()
        return
    ############################################################
    #  基本功能
    #  update 更新数据
    #  clear 清空数据
    ############################################################

    def update(self,data:dict) -> None:
        self.latest = data.copy()
        return

    def clear(self) -> None:
        self.latest = {
                'time_stamp': 0,
                
                'pitch': 0,
                'yaw': 0,

            }
        return

class Buff_Data():
    def __init__(self) -> None:
        self.clear()
        return
    ############################################################
    #  基本功能
    #  update 更新数据
    #  clear 清空数据
    ############################################################

    def update(self,data:dict) -> None:
        self.latest = data.copy()
        return
    
    def clear(self) -> None:
        self.latest = {
                'time_stamp': 0,
                
                'recovery_buff': 0,
                'cooling_buff': 0,
                'defence_buff': 0,
                'vulnerability_buff': 0,
                'attack_buff': 0,
                'remaining_energy': 0,
            }
        return

class Robot_Cmd_Data():
    def __init__(self) -> None:
        self.clear()
        return
    ############################################################
    #  基本功能
    #  update 更新数据
    #  clear 清空数据
    ############################################################

    def update(self,data:dict) -> None:
        self.latest = data.copy()
        return

    def clear(self) -> None:
        self.latest = {
                'time_stamp': 0,
                'speed_vector': {
                        'vx': 0,
                        'vy': 0,
                        'wz': 0,
                        },
                'chassis': {
                        'roll': 0,
                        'yaw': 0,
                        'pitch': 0,
                        'leg_length': 0,
                        },
                'gimbal': {
                        'yaw': 0,
                        'pitch': 0,
                        },
                'shoot': {
                        'fire': 0,
                        'fric_on': 0,
                        },
            }
        return
    




